package com.zyw.module.console.user.service;

import com.zyw.module.console.user.dao.UserDao;
import com.zyw.module.console.user.po.User;
import com.zyw.mvc.support.BaseService;
import com.zyw.orm.support.page.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService extends BaseService<User, Integer, UserDao> {

    public User get(Integer id) {
        return getDao().selectByPrimaryKey(id);
    }

    @Transactional
    public int insert(User record) {
        return getDao().insert(record);
    }

    @Transactional
    public int update(User record) {
        return getDao().updateByPrimaryKeySelective(record);
    }

    @Transactional
    public int delete(Integer id) {
        return getDao().deleteByPrimaryKey(id);
    }

    public List<User> findByPage(Page<User> page) {
        List<User> list = getDao().findByPage(page);
        page.setList(list);
        return list;
    }

    public List<User> findByUsername(String username) {
        return getDao().findByUsername(username);
    }

    public User findByWxUserid(String wxUserId) {
        return getDao().findByWxUserid(wxUserId);
    }

    public User findByUserName(String username) {
        return getDao().findByUserName(username);
    }

    /**
     * 根据用户名查询用户的密码
     *
     * @param username 用户名
     * @return pass
     */
    public String getPassword(String username) {
        return getDao().getPassword(username);
    }

    public List<User> findByPhone(String phone) {
        return getDao().findByPhone(phone);
    }

    public List<User> findByMiniappOpenid(String openid) {
        return null;
    }
}